package com.micangcaihang.micang.mvp.task.model;

import com.micangcaihang.common.baserx.RxSchedulers;
import com.micangcaihang.common.http.ApiResult;
import com.micangcaihang.common.http.RxHelper;
import com.micangcaihang.micang.entity.ReBackEntity;
import com.micangcaihang.micang.http.ApiService;
import com.micangcaihang.micang.http.FApiService;
import com.micangcaihang.micang.mvp.task.contract.DTaskDetailContract;

import java.util.List;

import io.reactivex.Observable;

/**
 * <pre>
 *     author : Fandy
 *     e-mail : fandayongfly@gmail.com
 *     time   : 2017/07/17
 *     desc   :
 *     version: 1.0
 * </pre>
 */

public class DTaskDetailModel implements DTaskDetailContract.Model {
    /**
     * 提交工单
     *
     * @param id     工单id
     * @param reback 退回工单id 没有传0
     * @return
     */
    @Override
    public Observable<ApiResult<Void>> commitData(String id, String reback) {
        return ApiService.<ApiResult<Void>>invest_submitorder(id, reback)
                .compose(RxSchedulers.observableIoToMain())
                .compose(RxHelper.handleResult());
    }

    /**
     * 工单退回原因
     *
     * @param id 工单id
     * @return
     */
    @Override
    public Observable<ApiResult<List<ReBackEntity>>> getRebackData(String id, String type) {
        return FApiService.<ApiResult<List<ReBackEntity>>>biz_returnreason(id, "3", type)
                .compose(RxSchedulers.observableIoToMain())
                .compose(RxHelper.handleResult());
    }
}
